var app = getApp();
var WxParse = require('../../../lib/wxParse/wxParse.js');
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    id: 0,
    itemId: 0,
    receipt: {},
    imgs: []
  },
  onLoad: function (options) {},
  onReady: function () {

  },
  onShow: function () {
    // 页面显示
    this.checkShopInfo();
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  /**
   * 用户认证信息检查{未认证用户：跳转到商户认证界面，已认证用户跳转到首页}
   */
  checkShopInfo: function () {
    util.getQualificationsInfo(function (user) {
      let shopInfo = wx.getStorageSync('shopInfo');
      if (shopInfo) {
        wx.switchTab({
          url: '/pages/index/index'
        });
      } else {
        wx.showLoading({
          title: '加载中...',
        });
        util.request(api.CouuntTargetStatus, {
          status: 0
        }).then(function (res) {
          wx.hideLoading();
          if (res.errno === 0) {
            if (res.data > 0) {
            } else {
              wx.reLaunch({
                url: "/pages/auth/authenticationIdentity/authenticationIdentity"
              });
            }
          }
        });
      }
    });
  },
  goLogin() {
    if (app.globalData.hasLogin) {
      this.checkShopInfo();
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  },
  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.goLogin();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
})